<template>
  <el-dialog
    :close-on-click-modal="false"
    :visible="dialogVisible"
    title="刀具报警"
    width="50%"
    :before-close="handleClose"
  >
    <vab-query-form>
      <vab-query-form-right-panel :span="24">
        <el-form
          label-width="49px"
          :inline="true"
          :model="queryForm"
          @submit.native.prevent
        >
          <el-form-item label="类型">
            <el-select v-model="queryForm.Type" placeholder="请选择">
              <el-option
                v-for="item in Types"
                :key="item"
                :label="item"
                :value="item"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="直径">
            <el-select v-model="queryForm.Diameter" placeholder="请选择">
              <el-option
                v-for="item in Diameters"
                :key="item"
                :label="item"
                :value="item"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="R角">
            <el-select v-model="queryForm.Rangle" placeholder="请选择">
              <el-option
                v-for="item in Rangles"
                :key="item"
                :label="item"
                :value="item"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="刃长">
            <el-select v-model="queryForm.BladeLengt" placeholder="请选择">
              <el-option
                v-for="item in BladeLengths"
                :key="item"
                :label="item"
                :value="item"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="材质">
            <el-select v-model="queryForm.Material" placeholder="请选择">
              <el-option
                v-for="item in Materials"
                :key="item"
                :label="item"
                :value="item"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="queryData">
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>
    <el-table :data="list" style="width: 100%">
      <el-table-column label="类型" prop="Type" />
      <el-table-column label="直径" prop="Diameter" />
      <el-table-column label="R角" prop="Rangle" />
      <el-table-column label="刃长" prop="BladeLength" />
      <el-table-column label="材质" prop="Material" />
      <el-table-column label="阈值" prop="AlarmNum" />
      <el-table-column label="库存" prop="Num" />
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNo"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <template slot="footer">
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <!-- <template>
          <el-button type="primary" @click="submit">确认</el-button>
        </template> -->
      </span>
    </template>
  </el-dialog>
</template>

<script>
  import {
    KnifeInfoThresholdList,
    SerachItemList,
    AlarmKnifeInfoList,
  } from '@/api/material'
  export default {
    data() {
      return {
        queryForm: {
          pageNo: 1,
          pageSize: 10,
          Type: '',
          Diameter: '',
          Rangle: '',
          BladeLength: '',
          Material: '',
        },

        Types: [],
        BladeLengths: [],
        Diameters: [],
        Rangles: [],
        Materials: [],
        list: [],
        total: 0,
        queryForm: {
          pageNo: 1,
          pageSize: 10,
          Type: '',
          Diameter: '',
          Rangle: '',
          BladeLength: '',
          Material: '',
        },

        layout: 'total, sizes, prev, pager, next, jumper',
        dialogVisible: false,
      }
    },
    mounted() {
      this.fetchData()
    },
    methods: {
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.fetchData()
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      show() {
        console.log('aaaaaaaaaaaaaaaaaaa')
        this.dialogVisible = true
        this.query()
        this.fetchData()
      },
      handleClose() {
        this.dialogVisible = false
      },
      query() {
        SerachItemList().then((res) => {
          this.Types = res.Types.filter((v) => v)
          this.BladeLengths = res.BladeLengths.filter((v) => v)
          this.Diameters = res.Diameters.filter((v) => v)
          this.Rangles = res.Rangles.filter((v) => v)
          this.Materials = res.Materials.filter((v) => v)
        })
      },
      queryData() {
        this.fetchData()
      },
      fetchData() {
        const params = {
          Index: this.getPage(this.queryForm.pageNo, this.queryForm.pageSize),
          Count: this.queryForm.pageSize,
          Type: this.queryForm.Type,
          Diameter: this.queryForm.Diameter,
          Rangle: this.queryForm.Rangle,
          BladeLength: this.queryForm.BladeLength,
          Material: this.queryForm.Material,
        }
        AlarmKnifeInfoList(params).then((res) => {
          console.log(res)
          this.list = res.AlarmKnifeInfo
          this.total = res.TotalCount
        })
      },
    },
  }
</script>

<style lang="scss" scoped></style>
